package com.c.ctgproject.adapter.guang

import android.content.Context
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.Button
import android.widget.RelativeLayout
import android.widget.TextView
import androidx.appcompat.widget.LinearLayoutCompat
import androidx.recyclerview.widget.RecyclerView
import com.c.ctgproject.R
import com.c.ctgproject.databinding.ItemCarHandlerDetail1Binding
import com.c.ctgproject.databinding.ItemCarHandlerDetail2Binding
import com.c.ctgproject.entity.guang.CARHandlerDetailListEntity
import com.c.ctgproject.utils.handlerNull
import com.c.ctgproject.utils.noDataHandler
import java.lang.StringBuilder

class CarHandlerDetailAdapter2(private val context: Context, private val mList: List<CARHandlerDetailListEntity.CarDismantleOrderBean.InfoListBean>) : RecyclerView.Adapter<CarHandlerDetailAdapter2.MyViewHolder>() {


    inner class MyViewHolder(view: ItemCarHandlerDetail2Binding) : RecyclerView.ViewHolder(view.root) {
        val mCodeTV: TextView = view.mCodeTV
        val mPartTV: TextView = view.mPartTV
        val carPlate: TextView = view.carPlate
        val mCarEngineTV:TextView=view.mCarEngineTV
        val mCarEngineLL:LinearLayoutCompat=view.mCarEngineLL
    }

    override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): MyViewHolder {
        val binding = ItemCarHandlerDetail2Binding.inflate(LayoutInflater.from(context), parent, false)
        return MyViewHolder(binding)
    }

    override fun onBindViewHolder(holder: MyViewHolder, position: Int) {
        val data = mList[position]
        holder.mCodeTV.text = data.carCode.noDataHandler()
        holder.carPlate.text = data.carPlate.noDataHandler()
        holder.mPartTV.text = data.myStr.noDataHandler()
        if(data.carEngine.handlerNull().isNotEmpty()){
            holder.mCarEngineLL.visibility=View.VISIBLE
            holder.mCarEngineTV.text=data.carEngine.noDataHandler()
        }else{
            holder.mCarEngineLL.visibility=View.GONE
        }




//            //拆解单状态 0-待拆解 1-拆解中 2-拆解完成
//            when (data.dismantleStatus) {
//                0 -> {
//                    holder.mStatusTV.textColorResource = R.color.colorAccent
//                    holder.mStatusTV.text = "待拆解"
//                    holder.mFinishRL.visibility=View.VISIBLE
//                    holder.mLine.visibility=View.VISIBLE
//                }
//                1 -> {
//                    holder.mStatusTV.text = "拆解中"
//                    holder.mStatusTV.textColorResource = R.color.red
//                    holder.mFinishRL.visibility=View.VISIBLE
//                    holder.mLine.visibility=View.VISIBLE
//                }
//                2 -> {
//                    holder.mStatusTV.textColorResource = R.color.gray_text
//                    holder.mStatusTV.text = "拆解完成"
//                    holder.mFinishRL.visibility=View.GONE
//                    holder.mLine.visibility=View.GONE
//                }
//                else -> {
//                    holder.mStatusTV.text = ""
//                    holder.mFinishRL.visibility=View.VISIBLE
//                    holder.mLine.visibility=View.VISIBLE
//                }
//            }
    }

    override fun getItemCount(): Int {
        return mList.size
    }
}